<?php
class TasksModule extends Module {
	public function index() {
		requireUser();
		$model = new TaskModel();
		$a = $model->getAllTasks();
		$this->set('tasks', $a);
		$this->render('tasks');
	}
	
	public function view($argv) {
		requireUser();
		if (count($argv) < 1) redirect(WEBROOT . '/tasks/');
		$id = $argv[0];
		$model = new TaskModel();
		$this->set('id', $id);
		$this->set('content', $model->getTaskHTML($id));
		$this->render('task');
	}
	
	public function pdf($argv) {
		requireUser();
		if (count($argv) < 1) redirect(WEBROOT . '/tasks/');
		$id = $argv[0];
		$model = new TaskModel();
		$status = download_document($model->getPDF($id), 'application/pdf');
		if (!$status) {
			$this->render('404');
		}
	}
	
	public function doc($argv) {
		requireUser();
		if (count($argv) < 1) redirect(WEBROOT . '/tasks/');
		$id = $argv[0];
		$model = new TaskModel();
		$status = download_document($model->getDoc($id), 'application/msword');
		if (!$status) {
			$this->render('404');
		}
	}
}
